package pl.edu.pjwstk.kor.sbql4j.project3;

import pl.wcislo.sbql4j.db4o.Db4oSBQLQuery;
import com.db4o.ObjectContainer;

import org.apache.commons.collections.CollectionUtils;

import pl.edu.pjwstk.kor.database.Database;
import pl.edu.pjwstk.kor.database.Sbql4jQuery;
import pl.edu.pjwstk.kor.model.Employee;
import pl.edu.pjwstk.kor.model.Employee;
import pl.edu.pjwstk.kor.model.Rank;
import pl.edu.pjwstk.kor.model.Service;

import pl.wcislo.sbql4j.exception.*;
import pl.wcislo.sbql4j.java.model.compiletime.Signature.SCollectionType;
import pl.wcislo.sbql4j.java.model.runtime.*;
import pl.wcislo.sbql4j.java.model.runtime.Struct;
import pl.wcislo.sbql4j.java.model.runtime.factory.*;
import pl.wcislo.sbql4j.java.utils.ArrayUtils;
import pl.wcislo.sbql4j.java.utils.OperatorUtils;
import pl.wcislo.sbql4j.java.utils.Pair;
import pl.wcislo.sbql4j.lang.codegen.nostacks.*;
import pl.wcislo.sbql4j.lang.codegen.simple.*;




import pl.wcislo.sbql4j.lang.parser.expression.*;
import pl.wcislo.sbql4j.lang.parser.expression.OrderByParamExpression.SortType;
import pl.wcislo.sbql4j.lang.parser.terminals.*;
import pl.wcislo.sbql4j.lang.parser.terminals.operators.*;
import pl.wcislo.sbql4j.lang.types.*;
import pl.wcislo.sbql4j.lang.xml.*;
import pl.wcislo.sbql4j.model.*;
import pl.wcislo.sbql4j.model.collections.*;
import pl.wcislo.sbql4j.util.*;
import pl.wcislo.sbql4j.util.Utils;
import pl.wcislo.sbql4j.xml.model.*;
import pl.wcislo.sbql4j.xml.parser.store.*;

import java.util.*;
import java.util.Collection;


public class Project3Query_SbqlQuery3 {
    private com.db4o.ObjectContainer db;
    private List<java.lang.String> jobs;

    public Project3Query_SbqlQuery3(final com.db4o.ObjectContainer db,
        final java.lang.String[] jobs) {
        this.db = db;
        this.jobs = ArrayUtils.toList(jobs);
    }

    /**
     * original query='db.(Employee where job in(jobs))
                            minus db.(Employee where count(deals) > 2)'
     *
     * query after optimization='db.(Employee where getJob() in jobs) minus db.(Employee where  count(getDeals()) > 2)'
    */
    public java.util.Collection<pl.edu.pjwstk.kor.model.Employee> executeQuery() {
        com.db4o.ObjectContainer _ident_db = db;
        java.util.Collection<pl.edu.pjwstk.kor.model.Employee> _dotResult = (java.util.Collection<pl.edu.pjwstk.kor.model.Employee>) _ident_db.query(new Project3Query_SbqlQuery3Db4o0(
                    jobs));
        com.db4o.ObjectContainer _ident_db1 = db;
        java.util.Collection<pl.edu.pjwstk.kor.model.Employee> _dotResult1 = (java.util.Collection<pl.edu.pjwstk.kor.model.Employee>) _ident_db1.query(new Project3Query_SbqlQuery3Db4o1());
        Collection _minusLeftCol1 = new ArrayList(_dotResult);
        Collection _minusRightCol1 = new ArrayList(_dotResult1);
        java.util.Collection<pl.edu.pjwstk.kor.model.Employee> _queryResult = new java.util.ArrayList<pl.edu.pjwstk.kor.model.Employee>();
        _queryResult.addAll(CollectionUtils.subtract(_minusLeftCol1,
                _minusRightCol1));

        return _queryResult;
    }
}
